/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: PrintStreamCollector.java 491 2007-02-24 08:48:17Z jack.rybicki $
 */
package logmatcher.collectors;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Arrays;

import logmatcher.Collector;
import logmatcher.Configurable;
import logmatcher.InitializationException;
import logmatcher.InputFilter;
import logmatcher.LogEventListener;
import logmatcher.LogEventProducer;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.NotImplementedException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Class can be used to capture all System.out.print calls.
 * <p>
 * Usage:<p>
 * System.setOut(collector);
 *
 * @version $Revision: 491 $
 */
public class PrintStreamCollector extends PrintStream implements
		Collector, Configurable, LogEventProducer {
	
	private static final Log LOGGER =LogFactory.getLog(PrintStreamCollector.class);

	public PrintStreamCollector() {
		super(new OutputStream(){

			/**
			 * @see java.io.OutputStream#write(int)
			 */
			@Override
			public void write(int b) throws IOException {
				//LOGGER.info((char)b);
			}});
	}

	/**
	 * @see logmatcher.Configurable#configure(org.apache.commons.configuration.Configuration, java.lang.String)
	 */
	public void configure(Configuration config, String id) throws InitializationException {
		throw new NotImplementedException();
		
	}

	/**
	 * @see java.io.PrintStream#print(java.lang.String)
	 */
	@Override
	public void print(String s) {
		LOGGER.info(s);
	}
	
	/**
	 * @see java.io.PrintStream#print(boolean)
	 */
	@Override
	public void print(boolean b) {
		LOGGER.info(b);
	}

	/**
	 * @see java.io.PrintStream#print(char)
	 */
	@Override
	public void print(char c) {
		LOGGER.info(c);
	}

	/**
	 * @see java.io.PrintStream#print(char[])
	 */
	@Override
	public void print(char[] s) {
		LOGGER.info(s);
	}

	/**
	 * @see java.io.PrintStream#print(double)
	 */
	@Override
	public void print(double d) {
		LOGGER.info(d);
	}

	/**
	 * @see java.io.PrintStream#print(float)
	 */
	@Override
	public void print(float f) {
		LOGGER.info(f);
	}

	/**
	 * @see java.io.PrintStream#print(int)
	 */
	@Override
	public void print(int i) {
		LOGGER.info(i);
	}

	/**
	 * @see java.io.PrintStream#print(long)
	 */
	@Override
	public void print(long l) {
		LOGGER.info(l);
	}

	/**
	 * @see java.io.PrintStream#print(java.lang.Object)
	 */
	@Override
	public void print(Object obj) {
		LOGGER.info(obj);
	}

	/**
	 * @see java.io.PrintStream#println()
	 */
	@Override
	public void println() {
		LOGGER.info("");
	}

	/**
	 * @see java.io.PrintStream#println(boolean)
	 */
	@Override
	public void println(boolean x) {
		LOGGER.info(x);
	}

	/**
	 * @see java.io.PrintStream#println(char)
	 */
	@Override
	public void println(char x) {
		LOGGER.info(x);
	}

	/**
	 * @see java.io.PrintStream#println(char[])
	 */
	@Override
	public void println(char[] x) {
		LOGGER.info(x);
	}

	/**
	 * @see java.io.PrintStream#println(double)
	 */
	@Override
	public void println(double x) {
		LOGGER.info(x);
	}

	/**
	 * @see java.io.PrintStream#println(float)
	 */
	@Override
	public void println(float x) {
		LOGGER.info(x);
	}

	/**
	 * @see java.io.PrintStream#println(int)
	 */
	@Override
	public void println(int x) {
		LOGGER.info(x);
	}

	/**
	 * @see java.io.PrintStream#println(long)
	 */
	@Override
	public void println(long x) {
		LOGGER.info(x);
	}

	/**
	 * @see java.io.PrintStream#println(java.lang.Object)
	 */
	@Override
	public void println(Object x) {
		LOGGER.info(x);
	}

	/**
	 * @see java.io.PrintStream#write(int)
	 */
	@Override
	public void write(int b) {
		LOGGER.info(b);
	}

	/**
	 * @see java.io.FilterOutputStream#write(byte[])
	 */
	@Override
	public void write(byte[] b) throws IOException {
		LOGGER.info(b);
	}

	/**
	 * @see java.io.PrintStream#println(java.lang.String)
	 */
	@Override
	public void println(String x) {
		LOGGER.info(x);
	}

	/**
	 * @see logmatcher.Collector#start()
	 */
	public void start() throws IOException {
		throw new NotImplementedException();
		
	}

	/**
	 * @see logmatcher.Collector#stop()
	 */
	public void stop() throws IOException {
		throw new NotImplementedException();
		
	}

	/**
	 * @see logmatcher.LogEventProducer#addLogEventListener(logmatcher.LogEventListener)
	 */
	public void addLogEventListener(LogEventListener listener) {
		throw new NotImplementedException();

	}

	/**
	 * @see logmatcher.LogEventProducer#addLogEventListener(logmatcher.LogEventListener, logmatcher.InputFilter)
	 */
	public void addLogEventListener(LogEventListener listener,
			InputFilter filter) {
		throw new NotImplementedException();

	}

}
